package com.fast.common.result;


import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * @Auther: lhy
 * @Date: 2021/11/11 12:48
 * @Mail: 190643201@qq.com
 */
public class ApiHelper {


    public static ApiResult SUCCESS() {
        ApiResult result = new ApiResult();
        result.setCode(ApiCode.SUCCESS.getCode());
        result.setMsg(ApiCode.SUCCESS.getMsg());
        return result;
    }

    public static ApiResult SUCCESS(String msg) {
        ApiResult result = SUCCESS();
        result.setMsg(msg);
        return result;
    }


    public static ApiResult ADD_SUCCESS() {
        ApiResult result = SUCCESS();
        result.setMsg(ApiCode.ADD_SUCCESS.getMsg());
        return result;
    }


    public static ApiResult PUT_SUCCESS() {
        ApiResult result = SUCCESS();
        result.setMsg(ApiCode.PUT_SUCCESS.getMsg());
        return result;
    }

    public static ApiResult DEL_SUCCESS() {
        ApiResult result = SUCCESS();
        result.setMsg(ApiCode.DEL_SUCCESS.getMsg());
        return result;
    }

    public static ApiResult GET_SUCCESS(Object data) {
        ApiDataResult result = new ApiDataResult();
        result.setData(data);
        result.setMsg(ApiCode.GET_SUCCESS.getMsg());
        return result;
    }


    public static <T> ApiResult PAGE_SUCCESS(IPage<T> page) {
        ApiPageResult result = new ApiPageResult();
        result.setMsg(ApiCode.GET_SUCCESS.getMsg());
        result.setData(page.getRecords());
        result.setTotal(page.getTotal());
        result.setCount(page.getPages());
        result.setCurrent(page.getCurrent());
        return result;
    }


    public static ApiResult FAIL(int code,String msg){
        ApiResult result = new ApiResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}
